import { register } from "../../api/index.js";

Page({
  data: {
    username: "",
    password: "",
    confirmPassword: "",
  },

  // 用户名输入处理
  usernameInput: function (e) {
    this.setData({
      username: e.detail.value,
    });
  },

  // 密码输入处理
  passwordInput: function (e) {
    this.setData({
      password: e.detail.value,
    });
  },
  confirmPasswordInput: function (e) {
    this.setData({
      confirmPassword: e.detail.value,
    });
  },
  async register() {
    if (this.data.password !== this.data.confirmPassword) {
      wx.showToast({ title: "密码不一致" });
      return;
    }

    const res = await register({
      username: this.data.username,
      password: this.data.password,
    });
    
    if (res.code === 200) {
      console.log("11111", res);
      wx.showToast({ title: "注册成功" });
      wx.navigateBack();
    }
    // 调用注册API
  
  },
});
